/*
 * commons is a based project implemented
 * Copyright (C) 2024 Jasmine
 */
package com.easy.core.redis.key;

import java.util.concurrent.TimeUnit;

import io.swagger.v3.oas.annotations.media.Schema;

/**
 * Redis基础key
 *
 * @author Jasmine
 * @since 1.0.0
 */
public abstract class BaseRedisKey implements RedisKey {

    @Schema(title = "key")
    private String key;

    @Schema(title = "过期时间(默认时间单位秒)")
    private int timeout;

    @Schema(title = "返回过期时间单位")
    private TimeUnit timeUnit;

    /**
     * 设置不过期的key
     */
    public BaseRedisKey(String key) {
        this.key = key;
    }

    /**
     * 过期key(默认时间单位秒)
     *
     * @param key
     * @param timeout 过期时间
     */
    public BaseRedisKey(String key, int timeout) {
        this.key = key;
        this.timeout = timeout;
        this.timeUnit = TimeUnit.SECONDS;
    }

    /**
     * 过期key
     *
     * @param key
     * @param timeout 过期时间
     * @param timeUnit 时间单位
     */
    public BaseRedisKey(String key, int timeout, TimeUnit timeUnit) {
        this.key = key;
        this.timeout = timeout;
        this.timeUnit = timeUnit;
    }

    @Override
    public String getKey() {
        return this.key;
    }

    @Override
    public int getTimeout() {
        return this.timeout;
    }

    @Override
    public TimeUnit getTimeUnit() {
        return this.timeUnit;
    }

    /*
    public String getPrefix() {
        String className = getClass().getSimpleName();
        return className + ":" + prefix;
    }*/
}
